<template>
    <div id="app">
        <div class="tag flex">
            <span class="item" :class="{ cur: !params.sortType }" @click="params.sortType = 0">热度排序</span>
            <span class="item" :class="{ cur: params.sortType }" @click="params.sortType = 1">舆情排序</span>
            <span style="color: #FFFFFF">{{ params.address }}</span>

        </div>
        <div class="main">

            <div class="container">
                <div class="item flex" v-for="item in dataList" :key="item.id">
                    <div class="curStock flex column shrink">
                        <p class="stockName flex column">
                            {{ item.newsInfoBlockFeeling.blockName }}
                        </p>
                        <p class="ratio flex column" :class="item.newsInfoBlockFeeling.color">
                            {{ item.newsInfoBlockFeeling.chgRatioStr }}
                        </p>
                    </div>
                    <div class="general flex column shrink">
                        <div class="title flex column"></div>
                        <div class="column clear">
                            <span class="label fl">成分股数</span>
                            <span class="num fl">{{ item.newsInfoBlockFeeling.constituentStockNum }}</span>
                            <span class="label fl">近1年事件数</span>
                            <span class="num fl">{{ item.newsInfoBlockFeeling.newsNum }}</span>
                        </div>
                        <div class="column clear">
                            <span class="label fl">上涨股票</span>
                            <span class="num fl red">{{ item.newsInfoBlockFeeling.upNum }}</span>
                            <span class="label fl">下跌股票</span>
                            <span class="num fl green">{{ item.newsInfoBlockFeeling.downNum }}</span>
                        </div>
                        <div class="column">
                            <span class="label">热度指数</span>
                            <span class="bar">
                            <!-- <span
                              class="progress org"
                              :style="{ width: item.blockHotValue + '%' }"
                            ></span> -->
                            <i class="icon hot"></i>
                            <span class="orange">{{ item.blockHotValue }}</span>
                            </span>
                        </div>
                        <div class="column">
                            <span class="label">舆情指数</span>
                            <span class="bar">
                            <!-- <span
                              class="progress blu"
                              :style="{ width: item.blockFeelingsValue + '%' }"
                            ></span> -->
                            <i class="icon blu"></i>
                            <span class="blue">{{ item.blockFeelingsValue }}</span>
                          </span>
                        </div>
                    </div>
                    <div class="hotStock flex column shrink">
                        <div class="title flex column"></div>
                        <div class="column clear" v-for="stock in item.stockList" :key="stock.id">
                            <span class="label fl stockName" @click="stockMarker(stock.blockId)">{{ stock.blockName }}</span>
                            <span class="num fl" :class="stock.color">{{ stock.chgRatioStr }}</span>
                            <span class="hoT fl">热度值:</span>
                            <span class="hoN fl orange">{{ stock.blockHotValue }}</span>
                        </div>
                    </div>
                    <div class="news flex column grow">
                        <div class="title flex column"></div>
                        <div class="n_item flex" v-for="news in item.newInfoItemList.slice(0, 4)" :key="news.id" @click="onDetail(news)">
                            <span class="articleTitle">{{ news.title }}</span>
                            <span class="time shrink">[{{ news.time }}]</span>
                        </div>
                    </div>
                    <div class="intro flex column grow">
                        <div class="title flex column"></div>
                        <div class="detail" v-html="item.brief"></div>
                    </div>
                </div>
            </div>
            <div v-if="total">
                <mPage @onPage="onPage" :pageSize.sync="params.pageSize" :currentPage.sync="params.pageNo" :total="total"></mPage>
            </div>
        </div>
    </div>
</template>
<script>
import mPage from "../components/mPage";
import {getMonitorList} from "../api/index";
import {stockPush} from "../script/utils";
import {openWeb} from "../../../common/common";

export default {
    components: {mPage},
    data() {
        return {
            total: 0,
            dataList: [],
            params: {
                sortType: 0,
                pageSize: 5,
                pageNo: 1,
                address: ''
            },
        };
    },
    watch: {
        "params.sortType"() {
            this.params.pageNo = 1;
            this.getMonitorList();
        },
    },
    mounted() {
        this.getMonitorList();
    },
    methods: {
        onPage(page) {
            this.params.pageNo = page;
            this.getMonitorList();
        },
        stockMarker(stock) {
            const setcode = String(stock).match(/^\d{3}/)[0] == "200" ? "0" : "1";
            const code = String(stock).match(/\d{6}$/)[0];
            window.prompt(
                "",
                `up://["open.stock",${Date.now()},{"setcode":"${setcode}","code":"${code}","type":"舆情监控"}]`
            );
        },
        handler(data) {
            const plateStock = data.map((item) => ({
                blockId: item.newsInfoBlockFeeling.blockId,
                stock: item.stockList ? item.stockList.map((it) => it.blockId) : [],
            }));
            const key = `plateStock_${this.params.sortType}_${
                this.params.pageNo - 1
            }`;
            stockPush({
                id: key,
                codes: plateStock,
                source: data,
                callback: ({id, value}) => {
                    if (id == key) {
                        this.dataList = value;
                    }
                },
            });
        },
        onDetail(item) {
            let {guid = '', stockId = '', kcType = ''} = item;
            let address = this.urlAbsolute(`/republic/index.html#/republic?newsId=${guid}&stockId=${stockId}&kcType=${kcType}`);
            openWeb(address, '题材新闻', 1);
            /*window.prompt(
                "",
                `up://["open.web",${Date.now()},{"url":"${path}/client/republic.htm#/republic/${newsId}","title":"题材新闻","popuptype":${type}}]`
            );*/
        },
        async getMonitorList() {
            const send = {
                ...this.params,
                pageNo: this.params.pageNo - 1,
            };
            await getMonitorList(send).then((back) => {
                if (back.status == 1) {
                    let list = back.data.list;
                    this.total = back.data.total;
                    this.handler(list);
                }
            });
        },
    },
};
</script>
<style scoped lang="scss">
#app {
    .tag {
        background: #1c1d21;
        border: 1px solid #0c0e17;
        height: 49px;
        align-items: center;

        .item {
            width: 115px;
            margin-left: 10px;
            height: 35px;
            background: url($PIC_URL + "/tlbypcWeb/republic/btn_bg.png") no-repeat center;
            text-align: center;
            line-height: 35px;
            font-size: 15px;
            color: #fff;
            cursor: pointer;
            background-position: 0;

            &:hover {
                background-position: -115px 0;
            }

            &.cur {
                background-position: -230px 0;
            }
        }
    }

    .main {
        padding: 13px;

        .container {
            border: 1px solid #27282e;

            .item {
                height: 160px;
                border-bottom: 1px solid #27282e;
                align-items: flex-start;
                padding-left: 13px;
                padding-top: 15px;
                box-sizing: border-box;

                .red {
                    color: #ea2827 !important;
                }

                .green {
                    color: #31ed24 !important;
                }

                .orange {
                    color: #ff8a00 !important;
                }

                .blue {
                    color: #36c8ff !important;
                }

                &:last-child {
                    border-bottom: none;
                }

                .curStock {
                    width: 271px;
                    height: 127px;
                    background: url($PIC_URL + "/tlbypcWeb/republic/bg.png") no-repeat;
                    justify-content: center;
                    align-items: center;

                    .stockName {
                        font-size: 24px;
                        color: #fdba6b;
                        line-height: 28px;
                        padding-bottom: 5px;
                    }

                    .ratio {
                        font-size: 22px;
                        line-height: 28px;
                        color: #ea2827;
                    }
                }

                .general {
                    width: 272px;
                    position: relative;
                    padding-left: 16px;
                    line-height: 26px;

                    .title {
                        height: 24px;
                        background: url($PIC_URL + "/tlbypcWeb/republic/tcgk.png") no-repeat;
                    }

                    .label {
                        font-size: 15px;
                        color: #bcbfc4;
                        display: inline-block;
                        min-width: 60px;
                    }

                    .num {
                        display: inline-block;
                        min-width: 50px;
                        text-align: center;
                        color: #ffffff;
                        font-size: 15px;
                    }

                    .bar {
                        // width: 141px;
                        font-size: 14px;
                        // display: inline-block;
                        // white-space: nowrap;
                        margin-left: 11px;

                        .icon {
                            display: inline-block;
                            position: relative;
                            top: 1px;
                            margin-right: 5px;

                            &.hot {
                                background: url($PIC_URL + "/tlbypcWeb/republic/redu.png") no-repeat center;
                                width: 14px;
                                height: 16px;
                            }

                            &.blu {
                                background: url($PIC_URL + "/tlbypcWeb/republic/yuqing.png") no-repeat center;
                                width: 15px;
                                height: 16px;
                            }
                        }
                    }

                    &::after {
                        content: "";
                        position: absolute;
                        width: 1px;
                        height: 132px;
                        background: #27282e;
                        right: 0;
                        top: 0;
                    }
                }

                .hotStock {
                    width: 272px;
                    position: relative;
                    padding-left: 18px;
                    line-height: 26px;

                    .title {
                        height: 24px;
                        background: url($PIC_URL + "/tlbypcWeb/republic/tcrg.png") no-repeat;
                    }

                    .stockName {
                        cursor: pointer;
                        margin-right: 5px;
                    }

                    .label {
                        font-size: 15px;
                        color: #f4f636;
                        display: inline-block;
                        min-width: 60px;
                    }

                    .num {
                        width: 60px;
                        color: #ffffff;
                        text-align: right;
                        font-size: 15px;
                    }

                    .hoT {
                        font-size: 15px;
                        color: #cccccc;
                        display: inline-block;
                        min-width: 60px;
                        padding-left: 24px;
                    }

                    .hoN {
                        width: 30px;
                        font-size: 15px;
                        color: #ffffff;
                    }

                    //   .bar {
                    //     width: 81px;
                    //     font-size: 14px;
                    //     display: inline-block;
                    //     white-space: nowrap;
                    //     margin-left: 11px;
                    //     .progress {
                    //       display: inline-block;
                    //       position: relative;
                    //       top: 1px;
                    //       height: 12px;
                    //       &.org {
                    //         background: linear-gradient(to left, #ffa133, #da2406);
                    //       }
                    //       &.blu {
                    //         background: linear-gradient(to right, #005dff, #36c8ff);
                    //       }
                    //     }
                    //   }
                    &::after {
                        content: "";
                        position: absolute;
                        width: 1px;
                        height: 132px;
                        background: #27282e;
                        right: 0;
                        top: 0;
                    }
                }

                .news {
                    max-width: 567px;
                    min-width: 300px;
                    position: relative;
                    line-height: 28px;

                    .title {
                        margin-left: 16px;
                        height: 24px;
                        background: url($PIC_URL + "/tlbypcWeb/republic/tcxw.png") no-repeat;
                    }

                    .n_item {
                        font-size: 15px;
                        color: #bcbfc4;
                        padding: 0 15px;
                        justify-content: space-between;
                        cursor: pointer;

                        .articleTitle {
                            white-space: nowrap;
                            overflow: hidden;
                            text-overflow: ellipsis;
                        }

                        &.cur {
                            background: #1d202c;
                            color: #ffffff;
                        }

                        &:hover {
                            background: #2d3245;
                            color: #ffffff;
                        }
                    }

                    &::after {
                        content: "";
                        position: absolute;
                        width: 1px;
                        height: 132px;
                        background: #27282e;
                        right: 0;
                        top: 0;
                    }
                }

                .intro {
                    max-width: 437px;
                    min-width: 200px;
                    position: relative;
                    line-height: 28px;

                    .title {
                        margin-left: 16px;
                        height: 24px;
                        background: url($PIC_URL + "/tlbypcWeb/republic/tcji.png") no-repeat;
                    }

                    .detail {
                        padding: 0 15px;
                        height: 103px;
                        overflow: hidden;
                        overflow-y: auto;
                        text-align: justify;
                        font-size: 16px;
                        color: #ff8a00;
                        line-height: 24px;
                    }
                }
            }
        }
    }
}
</style>
